home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 750 < prev    next >
Internet Message Format  |  1996-08-06  |  3KB

  1. Path: fido.asd.sgi.com!austern
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.std.c++,comp.std.c
  4. Subject: Re: Array function params and const qualifier
  5. Date: 15 Apr 1996 09:36:48 PDT
  6. Organization: Comp Sci, University of Melbourne
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4kr7qv$909@mulga.cs.mu.OZ.AU>
  9. References: <4ke06a$rp3@mozart.wg.icl.co.uk> <4kjqqa$bol@engnews1.Eng.Sun.COM> <u9ratts5oh.fsf@yorick.cygnus.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 14 Apr 1996 16:06:55 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMXJ7IEy4NqrwXLNJAQHJ3gH/UfWegKGXLfDv9GDiNViLnlPcBvGHzisA
  14.     CgSS+LRNbDvvq+X8/9Iz7yqltyGnIp1/P7qtv4khyHGRrnD4HZVb1g==
  15.     =c59c
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. [Note: this article is crossposted to comp.std.c++ and comp.std.c.]
  19.  
  20. In comp.std.c++, jason@cygnus.com (Jason Merrill) writes:
  21.  
  22. >>>>>> Steve Clamage <clamage@Eng.Sun.COM> writes:
  23. >
  24. >> Adel El-Beik <A.El-Beik@man0506.wins.icl.co.uk> writes:
  25. >>> I have a question concerning MSVC++ v.4.00 and the April DWP C++.
  26. [...]
  27. >>> C:\array\array.cpp(16) : error C2664: 'func' : cannot convert parameter 1 
  28. >>> from 'long [2][2]' to 'const long [][2]' (new behavior; please see help)
  29. >
  30. >> You have run into effectively the same rule that prohibits implicit
  31. >> conversion from "T**" to "const T**". That prohibition is not new,
  32. >> but is in the ISO/ANSI C standard, and has not been changed, since
  33. >> it would open a hole in the type system.
  34. >
  35. >But converting long (*)[2] to const long (*)[2] is more like converting
  36. >long ** to const long *const * than it is like converting long ** to const
  37. >long **, because there is no way to modify the array -- there is, in fact,
  38. >no array entity in memory, only two longs.  A long (*)[2] points to two
  39. >longs, whereas a const long (*)[2] points to two const longs.  I don't see
  40. >a constness hole there.
  41. >
  42. >I suspect this is an oversight.
  43.  
  44. Yes, but the oversight is in the implementation, not in the standard.
  45. The conversion in question is allowed by the draft C++ standard.  (See
  46. my other post to comp.std.c++ in this thread for a detailed explanation.)
  47. The conversion is also allowed by a variety of other implementations,
  48. including cfront, gcc, and SGI C++ (EDG).
  49.  
  50. Interestingly, even though this conversion is presumably disallowed by
  51. the ANSI/ISO C standard, many supposedly conforming C compilers fail to
  52. issue a diagnostic for it.  Of the six I tried, only two issued any
  53. diagnostic, even with all the appropriate options for selecting ANSI
  54. conformance and enabling warnings.
  55.  
  56. Compiler    Options                        Diagnostic?
  57. --------    -------                        -----------
  58. GNU C        gcc -ansi -pedantic -Wall            No
  59. SGI C        cc -ansi -pedantic -fullwarn -wlint,p        No
  60. DEC OSF/1 C    cc -std1                    No
  61. DEC C        cc -std1 -migrate -check            No
  62. Sun C        cc -Xc -v                    Yes (warning)
  63. LCC        lcc -A -A                    Yes (error)
  64.  
  65. --
  66. Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
  67. WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
  68. PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
  69. ---
  70. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  71.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  72.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  73.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  74.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  75. ]
  76.